package com.zhiyun.test.base.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by user on 2019-5-27.
 */
public class PropUtil {

  public static String getProp(String fileName,String key) {
    Properties properties = new Properties();
    try {
      properties.load(new FileInputStream(fileName));
    } catch (IOException e) {
      e.printStackTrace();
    }
    return properties.getProperty(key);
  }

  public static void setProp(String fileName,String key, String value){
    Properties properties = new Properties();
    try {
      properties.load(new FileInputStream(fileName));
      FileOutputStream oFile = new FileOutputStream(fileName);//true表示追加打开
      properties.setProperty(key,value);
      properties.store(oFile, "The New properties file");
      oFile.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
